﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using eSYSU.Model;
using eSYSU.Business;

public partial class NewsComment : System.Web.UI.Page
{
    public int ccount; //评论总数

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack && Request.QueryString["NewsID"] != null)
        {
            iframe_CommentPage.Attributes["src"] = "CommentForm.aspx?Title="
                + NewsService.GetNewsById(Convert.ToInt32(Request["NewsID"])).title
                + "&ID=" + Request["NewsID"];

            PageInit();
        }
    }

    protected void PageInit()
    {
        string title = NewsService.GetNewsById(Convert.ToInt32(Request["NewsID"])).title;
        ccount = NewsCommentService.GetCommentCount(Convert.ToInt32(Request["NewsID"]));
        Page.Title = "评论：" + title;
        hl_Title.Text = title;
        hl_Title.NavigateUrl = "NewsReading.aspx?ID=" + Request["NewsID"];
        RepeaterInit(Request["NewsID"]);
    }


    protected void RepeaterInit(string newsID)
    {
        DataTable dt = NewsCommentService.GetCommentsByNewsID(Convert.ToInt32(newsID));
        Repeater_CommentList.DataBind();

        Repeater_HotCommentNews.DataSource = NewsCommentService.GetHotCommentNews(10);
        Repeater_HotCommentNews.DataBind();

        //Repeater分页部分
        int curpage = Convert.ToInt32(this.labPage.Text);
        PagedDataSource ps = new PagedDataSource();

        ps.DataSource = dt.DefaultView;
        ps.AllowPaging = true; //是否可以分页
        ps.PageSize = 10; //每页显示的数量
        ps.CurrentPageIndex = curpage - 1; //取得当前页的页码
        this.lnkbtnUp.Enabled = true;
        this.lnkbtnUp.CssClass = "enable";
        this.lnkbtnNext.Enabled = true;
        this.lnkbtnNext.CssClass = "enable";
        this.lnkbtnBack.Enabled = true;
        this.lnkbtnBack.CssClass = "enable";
        this.lnkbtnOne.Enabled = true;
        this.lnkbtnOne.CssClass = "enable";

        if (curpage == 1)
        {
            this.lnkbtnOne.Enabled = false;//不显示第一页按钮
            this.lnkbtnOne.CssClass = "disable";
            this.lnkbtnUp.Enabled = false;//不显示上一页按钮
            this.lnkbtnUp.CssClass = "disable";
        }
        if (curpage == ps.PageCount)
        {
            this.lnkbtnNext.Enabled = false;//不显示下一页
            this.lnkbtnNext.CssClass = "disable";
            this.lnkbtnBack.Enabled = false;//不显示最后一页
            this.lnkbtnBack.CssClass = "disable";
        }
        this.labBackPage.Text = Convert.ToString(ps.PageCount);
        this.Repeater_CommentList.DataSource = ps;
        this.Repeater_CommentList.DataBind();
    }


    //以下为分页按钮事件
    protected void lnkbtnOne_Click(object sender, EventArgs e)
    {
        this.labPage.Text = "1";
        this.PageInit();
    }
    protected void lnkbtnUp_Click(object sender, EventArgs e)
    {
        this.labPage.Text = Convert.ToString(Convert.ToInt32(this.labPage.Text) - 1);
        this.PageInit();
    }
    protected void lnkbtnNext_Click(object sender, EventArgs e)
    {
        this.labPage.Text = Convert.ToString(Convert.ToInt32(this.labPage.Text) + 1);
        this.PageInit();
    }
    protected void lnkbtnBack_Click(object sender, EventArgs e)
    {
        this.labPage.Text = this.labBackPage.Text;
        this.PageInit();
    }
}